// pages/user/info/info.js
import { uploadFile } from '../../../utils/alioss.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {
      headImg: '/images/active/Avatar.png',
      name: '',
      phone: '',
      lealName: '',
      sex: '',
      shippingAddress: '',
      address: '',
      date: '',
    }
  },
  /** * 生命周期函数--监听页面加载*/
  onLoad: function (options) {
    console.log(this.data.areaList)
    this.getUserInfo()
  },
  // 上传头像
  upHeadImg() {
    const that = this;
    //选取头像
    wx.chooseImage({
      count: 1,
      success(res) {

        let image = res.tempFilePaths[0];
        getApp().vants.Toast.loading({
          message:'加载中...',
          duration:0
        })
        console.log(image);
        uploadFile(image).then(function(res){
          if(res.status&& res.data.url){
            const url = "/user/front_user/edit_user_info"
            const params = {
              token: wx.getStorageSync('token'),
              head_img: res.data.url
            }
            getApp().requests(url,params,'post').then(() => {
              const info = that.data.info;
              info.headImg = res.data.url;
              that.setData({
                info
              });
              getApp().vants.Toast.success('修改成功!')
            }).catch(err=> {
              getApp().vants.Toast.fail(err);
            })
          }else{
            console.log(res,'??');
            getApp().vants.Toast.fail(res.errMsg);
          }

        },function(res){
          getApp().vants.Toast.fail(res.errMsg);
        });
      },
      fail(err){
        console.log(err);
      }
    })

  }
})